package com.njupt.swg.threadstudyjimin.item04.sync;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class SyncTest2 {

    public static void add1(int j){
        synchronized (SyncTest2.class){
            for(int i=0;i<10;i++){
                System.out.println(j+"---"+i);
            }
        }
    }

    public synchronized static void add2(int j){
        for(int i=0;i<10;i++){
            System.out.println(j+"---"+i);
        }
    }

    public static void main(String[] args) {
        SyncTest2 test1 = new SyncTest2();
        SyncTest2 test2 = new SyncTest2();
        ExecutorService executorService = Executors.newCachedThreadPool();
        executorService.execute(() -> {
            test1.add1(1);
        });
        executorService.execute(() -> {
            test2.add2(2);
        });
    }
}
